/**
 * @param {string[]} strs
 * @return {number}
 */
export var minDeletionSize = function (strs) {
  const flags = new Array(strs[0].length).fill(false)
  let ans = 0
  for (let r = 1; r < strs.length; r++) {
    const [prev, curr] = [strs[r - 1], strs[r]]
    for (let c = 0; c < curr.length; c++) {
      if (flags[c]) continue
      if (prev[c] > curr[c]) {
        flags[c] = true
        ans++
      }
    }
  }
  return ans
}

/**
 * @param {string[]} strs
 * @return {number}
 */
export var minDeletionSize2 = function (strs) {
  let ans = 0
  for (let c = 0; c < strs[0].length; c++) {
    for (let r = 1; r < strs.length; r++) {
      if (strs[r][c] < strs[r - 1][c]) {
        ans++
        break
      }
    }
  }
  return ans
}
